import { Space, Button, Switch } from 'antd';
import { IUser } from './types';
import type { ColumnsType } from 'antd/es/table';
export const columns = (edit: (info: object) => void, remove: (info: IUser) => void,changeStatus: ((info: IUser) => void)): ColumnsType<IUser> => {
    return [
        {
            title: '用户名',
            dataIndex: 'userName',
            width: 100
        },
        {
            title: '手机号',
            dataIndex: 'telephone',
            width: 100
        },
        {
            title: '角色名称',
            dataIndex: 'roleName',
            width: 80,
        },
        {
            title: '所属部门',
            dataIndex: 'deptName',
            render: (text: any) => `${text ? text : '无'}`,
            width: 100
        },
        {
            title: '状态',
            dataIndex: 'status',
            render: (text: any, row: IUser, index: number) => <Switch defaultChecked={text == 1 ? true : false} onChange={()=>changeStatus(row)} checkedChildren="开启" unCheckedChildren="关闭" />,
            width: 60
        },
        {
            title: '创建时间',
            dataIndex: 'createTime',
            render: (text: any) => `${text}`,
            width: 140
        },
        {
            title: '操作',
            width: 120,
            fixed: 'right',
            render: (text: any, row: IUser, index: number) => (
                <Space>
                    <Button type="primary" size='small' disabled={text.userType == 'super_admin'} onClick={() => edit(row)}>编辑</Button>
                    <Button type="primary" size='small' disabled={text.userType == 'super_admin'} danger onClick={() => remove(row)}>删除</Button>
                </Space>
            )
        }
    ];
}
